{extend name="base" /}
{block name="content"}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <li class="layui-this">课程模板库</li>
                <li class=""><a href="{:url('admin/dp/course_template_add')}">添加模板</a></li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <form class="layui-form" action="">
                        <table class="layui-table" lay-size="sm">
                            <thead>
                            <tr>
                                <th>ID</th>
                                <th>模板名称</th>
                                <th>专家</th>
                                <th>分类</th>
                                <th>介绍</th>
                                <th style="width: 150px;">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {foreach name="templates" item="vo"}
                            <tr>
                                <td>{$vo.id}</td>
                                <td>{$vo.name}</td>
                                <td>{$vo.expert_name}</td>
                                <td>{$vo.category_name}</td>
                                <td>{$vo.desc}</td>
                                <td>
                                    <div class="layui-btn-group">
                                        <a href="{:url('admin/dp/course_template_edit',['id'=>$vo.id])}" class="layui-btn layui-btn-sm" title="编辑"><i class="layui-icon">&#xe642;</i></a>
                                        <a href="{:url('admin/dp/course_template_delete',['id'=>$vo.id])}" class="layui-btn layui-btn-sm ajax-delete" title="删除"><i class="layui-icon">&#xe640;</i></a>
                                        <a href="{:url('admin/dp/course_add',['template_id'=>$vo.id])}" class="layui-btn layui-btn-sm layui-btn-normal" title="生成课程">生成</a>
                                    </div>
                                </td>
                            </tr>
                            {/foreach}
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}

{block name="js"}
<script>
    layui.use(['layer','form'], function(){
        var $ = layui.jquery, layer = layui.layer;
        var form = layui.form;

        $('.ajax-delete').on('click', function () {
            var _href = $(this).attr('href');
            layer.open({
                shade: false,
                content: '确定删除该模板？',
                btn: ['确定', '取消'],
                yes: function (index) {
                    $.ajax({
                        url: _href,
                        type: "get",
                        success: function (info) {
                            if (info.code === 1) {
                                window.location.reload()
                            }
                            layer.msg(info.msg);
                        }
                    });
                    layer.close(index);
                }
            });

            return false;
        });
    });
</script>
{/block}
